<!DOCTYPE html>
<html>
<head>
    <title>测试 /web/logs 路由</title>
    <script>
        async function testWebLogs() {
            try {
                // 首先获取token
                const loginResponse = await fetch('http://localhost:8001/api/v1/auth/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        username: 'admin',
                        password: 'admin123'
                    })
                });
                
                const loginData = await loginResponse.json();
                const token = loginData.access_token;
                
                // 使用token访问 /web/logs
                const response = await fetch(`http://localhost:8001/web/logs?token=${token}`);
                const text = await response.text();
                
                document.getElementById('result').innerHTML = `
                    <h3>测试结果:</h3>
                    <p><strong>状态码:</strong> ${response.status}</p>
                    <p><strong>响应长度:</strong> ${text.length} 字符</p>
                    <p><strong>页面标题:</strong> ${text.match(/<title>(.*?)<\/title>/)?.[1] || '未找到标题'}</p>
                    <p><strong>是否包含日志表格:</strong> ${text.includes('logsTableBody') ? '是' : '否'}</p>
                    <h4>页面内容预览:</h4>
                    <pre>${text.substring(0, 500)}...</pre>
                `;
                
                // 在新窗口中打开页面
                window.open(`http://localhost:8001/web/logs?token=${token}`, '_blank');
                
            } catch (error) {
                document.getElementById('result').innerHTML = `<p style="color: red;">错误: ${error.message}</p>`;
            }
        }
    </script>
</head>
<body>
    <h1>测试 /web/logs 路由</h1>
    <button onclick="testWebLogs()">测试 /web/logs 页面</button>
    <div id="result"></div>
</body>
</html>